package com.ak.mytest;

import com.ak.entity.JsonRootBean;
import com.ak.entity.Rows;
import com.ak.entity.Students;
import com.ak.utils.ConnectUtils;
import com.ak.utils.DateUtils;
import com.google.gson.Gson;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.junit.Test;

import javax.swing.text.html.StyleSheet;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;

public class MyLogin {

    public static String LOGIN_URL = "http://authserver.jit.edu.cn/authserver/login";

    @Test
    public void testU(){
          // 登陆
        Connection.Response login = ConnectUtils.login("http://authserver.jit.edu.cn/authserver/login", "1712041003", "133415");
        // 新增页面 url
        String index_url="http://ehallapp.jit.edu.cn/emapflow/sys/lwReportEpidemic/index.do";
        Connection.Response kk = ConnectUtils.response(index_url, login);
       // System.out.println(kk.body());

        // 获取所有数据的 url
        String url="http://ehallapp.jit.edu.cn/emapflow/sys/lwReportEpidemic/modules/newdailyReport/getMyNewDailyReportDatas.do";
        Connection.Response add = ConnectUtils.response(url, kk);
        Gson gson=new Gson();
        Students students=gson.fromJson(add.body(),Students.class);
        List<Rows> rows=students.getDatas().getGetMyNewDailyReportDatas().getRows();
        System.out.println(rows.get(0));
        // 获取健康信息打卡的所有数据
        // http://ehallapp.jit.edu.cn/emapflow/sys/lwReportEpidemic/modules/newdailyReport/getMyNewDailyReportDatas.do

        // 请求网址 http://ehallapp.jit.edu.cn/emapflow/sys/lwReportEpidemic/modules/newdailyReport/T_REPORT_EPIDEMIC_CHECKIN_SAVE.do
        Rows rows1=rows.get(0);
        JsonRootBean user=ConnectUtils.copyAttr(rows1,new JsonRootBean());

        // 只需要跟新这四个参数
        //        CZRQ: 2021-01-16 01:19:05
        // 打卡上次时间
        user.setCZRQ(rows1.getCREATED_AT());
//       打卡时间
        user.setNEED_CHECKIN_DATE(DateUtils.getsdfyyyy_MM_dd());
//     打卡具体时间
        user.setCREATED_AT(DateUtils.getSdfyyyy_MM_ddHHmm());
        // 设置年龄
        user.setDZ_NL(rows1.getDZ_NL());
        // 健康码为绿色
        user.setDZ_NGLJKM("1");
        user.setDZ_NGLJKM_DISPLAY("绿色");


        // 设置id
        user.setCREATED_AT(UUID.randomUUID().toString().substring(4));
        Gson gson1=new Gson();
        String data=gson1.toJson(user);

        String add_url="http://ehallapp.jit.edu.cn/emapflow/sys/lwReportEpidemic/modules/newdailyReport/T_REPORT_EPIDEMIC_CHECKIN_SAVE.do";

//        Connection.Response response = ConnectUtils.responseJsonParam(add_url, kk, data);
//        System.out.println(response.body());
//        if(response.statusCode()==200){
//            System.out.println("注册成功");
//        }
        // 数据
////        USER_ID: 1712041003
//        user.setUSER_ID(rows1.getUSER_ID());
////        USER_NAME: 李飞翔
//        user.setUSER_NAME(rows1.getUSER_NAME());
////        DZ_NL: 21
//        user.setDZ_NL(rows1.getDZ_NL());
////        GENDER_CODE_DISPLAY: 男
//        user.setGENDER_CODE_DISPLAY(rows1.getGENDER_CODE_DISPLAY());
////        GENDER_CODE: 1
//        user.setGENDER_CODE(rows1.getGENDER_CODE());
////        DEPT_CODE: 00000500312
//        user.setDEPT_CODE(rows1.getDEPT_CODE());
////        DEPT_NAME: 软件工程学院
//        user.setDEPT_NAME(rows1.getDEPT_NAME());
////        IDCARD_NO: 320826199909133415
//        user.setIDCARD_NO(rows1.getWID());
////        DZ_CLASS_CODE_DISPLAY: 17软件工程（与NIIT 合作嵌入式）
//        user.setDZ_CLASS_CODE_DISPLAY(rows1.getDZ_CLASS_CODE_DISPLAY());
////        DZ_CLASS_CODE: 17120411
//        user.setDZ_CLASS_CODE(rows1.getDZ_CLASS_CODE());
////        DZ_CLASS_NAME: 17软件工程（与NIIT 合作嵌入式）
//        user.setDZ_CLASS_NAME(rows1.getDZ_CLASS_NAME());
////        DZ_SFWX_DISPLAY:
//        user.setDZ_SFWX_DISPLAY(rows1.getDZ_SFWX_DISPLAY());
////        DZ_SFWX:
//        user.setDZ_SFWX(rows1.getDZ_SFWX());
////        DZ_RYXZ_DISPLAY: 本科生
//        user.setDZ_RYXZ_DISPLAY(rows1.getDZ_RYXZ_DISPLAY());
////        DZ_RYXZ: 9
//        user.setDZ_RYXZ(rows1.getDZ_RYXZ());
////        CZR: 1712041003
//        user.setCZR(rows1.getCZR());
////        CZZXM: 李飞翔
//        user.setCZZXM(rows1.getCZZXM());
////        CZRQ: 2021-01-16 01:19:05
//        user.setCZRQ(rows1.getCREATED_AT());
////        NEED_CHECKIN_DATE: 2021-01-17
//        user.setNEED_CHECKIN_DATE(DateUtils.getsdfyyyy_MM_dd());
////        CREATED_AT: 2021-01-17 08:21
//        user.setCREATED_AT(DateUtils.getSdfyyyy_MM_ddHHmm());
////        WID: B905152D05FA6ABDE05329C702DF68B8
//        user.setCREATED_AT(UUID.randomUUID().toString().substring(4));
////        DZ_SFFX_DISPLAY: 否
        user.setDZ_SFFX_DISPLAY("否");
////        DZ_SFFX: NO
        user.setDZ_SFFX("NO");
////        DZ_SFYC_DISPLAY: 否
      user.setDZ_SFYC_DISPLAY(rows1.getDZ_SFYC_DISPLAY());
////        DZ_SFYC: NO
        user.setDZ_SFYC("NO");
////        DZ_YCTWZ:
//        user.setDZ_YCTWZ(rows1.getDZ_YCTWZ());
////        DZ_SFFR_DISPLAY:
//        user.setDZ_SFFR_DISPLAY(rows1.getDZ_SFFR_DISPLAY());
////        DZ_SFFR:
//        user.setDZ_SFFR(rows1.getDZ_SFFR());
////        DZ_YQYZDQ:
//        user.setDZ_YQYZDQ(rows1.getDZ_YQYZDQ());
////        DZ_NGLJKM_DISPLAY: 绿色
//        user.setDZ_NGLJKM(rows1.getDZ_NGLJKM());
//        DZ_NGLJKM: 1
//        DZ_SFQGNJYWCS_DISPLAY: 否
        user.setDZ_SFQGNJYWCS_DISPLAY("否");
//        DZ_SFQGNJYWCS: NO
        user.setDZ_SFQGNJYWCS("NO");
//        DZ_ZJMYD: 江苏省/淮安市
//        DZ_CRSFFX_DISPLAY: 是
    user.setDZ_CRSFFX_DISPLAY("是");
//        DZ_CRSFFX: YES
        user.setDZ_CRSFFX("YES");
      //  user.setDZ_CRSFFX("");
//        DZ_SFZNJ_DISPLAY: 否
      user.setDZ_SFZNJ_DISPLAY("否");
//        DZ_SFZNJ: NO
        user.setDZ_SFZNJ("NO");
//        DZ_SFYZZN_DISPLAY:
//        DZ_SFYZZN:
//        DZ_LNSJ:
//        LOCATION_PROVINCE_CODE_DISPLAY: 江苏省
//        LOCATION_PROVINCE_CODE: 320000
//        LOCATION_CITY_CODE_DISPLAY: 淮安市
//        LOCATION_CITY_CODE: 320800
//        LOCATION_COUNTY_CODE_DISPLAY: 涟水县
//        LOCATION_COUNTY_CODE: 320826
//        LOCATION_DETAIL: 江苏省淮安市涟水县涟城镇安东路5号
//        HEALTH_UNSUAL_CODE:
//        SAW_DOCTOR_DESC:
//        MEMBER_HEALTH_UNSUAL_CODE:
//        DZ_SFDJYSBL:
//        DZ_SFDJQZBL:
//        DZ_SFYJCGL:
//        DZ_SFDW:

        System.out.println(user);
    }


    @Test
    public void kk(){
        System.out.println(UUID.randomUUID().toString().substring(4).length());
    }

    @Test
    public void tets(){
        String kk="        USER_ID: 1712041003\n" +
                "        USER_NAME: 李飞翔\n" +
                "        DZ_NL: 21\n" +
                "        GENDER_CODE_DISPLAY: 男\n" +
                "        GENDER_CODE: 1\n" +
                "        DEPT_CODE: 00000500312\n" +
                "        DEPT_NAME: 软件工程学院\n" +
                "        IDCARD_NO: 320826199909133415\n" +
                "        DZ_CLASS_CODE_DISPLAY: 17软件工程（与NIIT 合作嵌入式）\n" +
                "        DZ_CLASS_CODE: 17120411\n" +
                "        DZ_CLASS_NAME: 17软件工程（与NIIT 合作嵌入式）\n" +
                "        DZ_SFWX_DISPLAY:\n" +
                "        DZ_SFWX:\n" +
                "        DZ_RYXZ_DISPLAY: 本科生\n" +
                "        DZ_RYXZ: 9\n" +
                "        CZR: 1712041003\n" +
                "        CZZXM: 李飞翔\n" +
                "        CZRQ: 2021-01-16 01:19:05\n" +
                "        NEED_CHECKIN_DATE: 2021-01-17\n" +
                "        CREATED_AT: 2021-01-17 08:21\n" +
                "        WID: B905152D05FA6ABDE05329C702DF68B8\n" +
                "        DZ_SFFX_DISPLAY: 否\n" +
                "        DZ_SFFX: NO\n" +
                "        DZ_SFYC_DISPLAY: 否\n" +
                "        DZ_SFYC: NO\n" +
                "        DZ_YCTWZ:\n" +
                "        DZ_SFFR_DISPLAY:\n" +
                "        DZ_SFFR:\n" +
                "        DZ_YQYZDQ:\n" +
                "        DZ_NGLJKM_DISPLAY: 绿色\n" +
                "        DZ_NGLJKM: 1\n" +
                "        DZ_SFQGNJYWCS_DISPLAY: 否\n" +
                "        DZ_SFQGNJYWCS: NO\n" +
                "        DZ_ZJMYD: 江苏省/淮安市\n" +
                "        DZ_CRSFFX_DISPLAY: 是\n" +
                "        DZ_CRSFFX: YES\n" +
                "        DZ_SFZNJ_DISPLAY: 否\n" +
                "        DZ_SFZNJ: NO\n" +
                "        DZ_SFYZZN_DISPLAY:\n" +
                "        DZ_SFYZZN:\n" +
                "        DZ_LNSJ:\n" +
                "        LOCATION_PROVINCE_CODE_DISPLAY: 江苏省\n" +
                "        LOCATION_PROVINCE_CODE: 320000\n" +
                "        LOCATION_CITY_CODE_DISPLAY: 淮安市\n" +
                "        LOCATION_CITY_CODE: 320800\n" +
                "        LOCATION_COUNTY_CODE_DISPLAY: 涟水县\n" +
                "        LOCATION_COUNTY_CODE: 320826\n" +
                "        LOCATION_DETAIL: 江苏省淮安市涟水县涟城镇安东路5号\n" +
                "        HEALTH_UNSUAL_CODE:\n" +
                "        SAW_DOCTOR_DESC:\n" +
                "        MEMBER_HEALTH_UNSUAL_CODE:\n" +
                "        DZ_SFDJYSBL:\n" +
                "        DZ_SFDJQZBL:\n" +
                "        DZ_SFYJCGL:\n" +
                "        DZ_SFDW:";
        String []dd=kk.split("\n");
        StringBuilder d=new StringBuilder();
        d.append("{");
        for (String s:dd){
            System.out.println(s);
            String []mm=s.split(":");
            if(mm.length==2){
                d.append("\""+mm[0].trim()+"\""+": "+"\""+mm[1].trim()+"\""+",\n");
            }else {
                d.append("\""+mm[0].trim()+"\""+": "+"null,\n");
            }
        }

        d.append("}");
        System.out.println(d.toString());
    }
}
